package com.rogue.order.management.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.rogue.order.management.domain.HsOrder;
import com.rogue.order.management.domain.OrderPageDTO;
import com.rogue.order.management.service.HsOrderService;
import com.rogue.order.management.mapper.HsOrderMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Objects;

/**
* @author YeahLiang
* @description 针对表【hs_order(订单表)】的数据库操作Service实现
* @createDate 2022-03-16 15:42:12
*/
@Service
public class HsOrderServiceImpl extends ServiceImpl<HsOrderMapper, HsOrder>
    implements HsOrderService{

    @Resource
    private HsOrderMapper hsOrderMapper;

    @Override
    public PageInfo<HsOrder> listOrder(OrderPageDTO orderPageDTO) {
        final PageInfo<HsOrder> pageInfo = PageHelper.startPage(orderPageDTO.getPage(), orderPageDTO.getCount()).doSelectPageInfo(() ->
                hsOrderMapper.selectList(new QueryWrapper<HsOrder>().lambda()
                        .eq(Objects.nonNull(orderPageDTO.getMemberId()), HsOrder::getMemberId, orderPageDTO.getMemberId())
                        .eq(Objects.nonNull(orderPageDTO.getDeptId()), HsOrder::getDeptId, orderPageDTO.getDeptId())
                        .eq(Objects.nonNull(orderPageDTO.getOrderType()), HsOrder::getOrderType, orderPageDTO.getOrderType())
                        .eq(Objects.nonNull(orderPageDTO.getOrderStatus()), HsOrder::getOrderStatus, orderPageDTO.getOrderStatus())
                        .like(StrUtil.isNotBlank(orderPageDTO.getMemberName()), HsOrder::getMemberNickname, orderPageDTO.getMemberName())
                )
        );
        return pageInfo;
    }
}




